package com.axonactive.yolo.webservice;

import java.io.IOException;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;

import com.axonactive.yolo.webservice.utils.Utils;

@Path("/subscribe")
public class Subscribe {

	/**
	 * @param 
	 * KEY: subscribeListParam
	 * VALUE: {"userId":300,"timeStamp":"1399281563703"}
	 * @return
	 * @throws IOException
	 * @throws InterruptedException
	 */
	@POST
	@Path("/list")
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	@Produces(MediaType.APPLICATION_JSON)
	public String getSubscribedFlightList(MultivaluedMap<String, String> param)
			throws IOException, InterruptedException {
		return Utils.call("subscribe_list/" + Utils.encode(param.getFirst("subscribeListParam")));
	}
	
	/**
	 * @param
	 * {
		"userId":5,
		"flightId":"BL591DADSGN17/4/2014$?$0",
		"outboundCode":"DAD",
		"outboundName":"Da Nang",
		"inboundCode":"SGN",
		"inboundName":"Tan Son Nhat International",
		"outBoundDate":"2014/04/17",
		"inBoundDate":"2014/04/17",
		"typeOfTrip":"oneWay",
		"numberAdult":1,
		"numberChild":0,
		"numberInfant":0,
		"classType":"0",
		"numberStops":2,
		"price":1973.0,
		"priceProvider":"Jetstar",
		"currencyCode":"RUB",
		"unixDepartureTime":"1397718600",
		
		"outBoundNumStops":0,
		"outBoundDuration":75,
		"outBoundFlightNumber":"BL591",
		"outBoundCarriers":"Pacific Airlines",
		"outBoundAirportsExpanded":"DAD-SGN",
		"outBoundDepartureTime":"07:10",
		"outBoundArrivalTime":"08:25",
		"outBoundDayOver":0,
		
		"inBoundNumStops":0,
		"inBoundDuration":0,
		"inBoundFlightNumber":null,
		"inBoundCarriers":null,
		"inBoundAirportsExpanded":null,
		"inBoundDepartureTime":null,
		"inBoundArrivalTime":null,
		"inBoundDayOver":0
		}
	 * @return
	 * @throws IOException
	 * @throws InterruptedException
	 */
	@POST
	@Path("/do")
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	@Produces(MediaType.APPLICATION_JSON)
	public String subscribe(MultivaluedMap<String, String> param)
			throws IOException, InterruptedException {
		return Utils.call("subscribe/" + Utils.encode(param.getFirst("subscribeParam")));
	}
	
	/**
	 * @param
	 * {
		"userId":5,
		"flightId":"BL591DADSGN17/4/2014$?$0"
		}
	 * @return
	 * @throws IOException
	 * @throws InterruptedException
	 */
	@POST
	@Path("/unsubscribe")
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	@Produces(MediaType.APPLICATION_JSON)
	public String unsubscribe(MultivaluedMap<String, String> param)
			throws IOException, InterruptedException {
		return Utils.call("unsubscribe/" + Utils.encode(param.getFirst("unsubscribeParam")));
	}
}
